<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$taskid=intval($_RQ['taskid']);
	$workermid=intval($_RQ['workermid']);
	if(!$taskid && !$workermid){
		exi('未传ID无法评价！','error');
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if($taskid){
		$params['taskid']=$taskid;
	}
	if($workermid){
		$params['workermid']=$workermid;
	}
	$item=$this->pdo_get('survey',$params); 
	if(!$item['id']){
		$item['taskid']=$taskid;
		$item['workermid']=$workermid;
	}
	$return['item']=$item;
	set_html('title','满意度调查');
	exi($return);
}

if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	$data=array(
		'msg'=>$postdata['msg'],
		'images'=>ijson_encode($postdata['images']),
		'star'=>intval($postdata['star']),
	);
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if($postdata['taskid']){
		$params['taskid']=$postdata['taskid'];
	}
	if($postdata['workermid']){
		$params['workermid']=$postdata['workermid'];
	}
	$comment_id=$this->pdo_getcolumn('survey',$params,'id');
	if($comment_id){
		if($postdata['pingjia']==1){
			exi('该评价已生效显示，不可修改！','error','goback');
		}
		$this->pdo_update('survey',$data,array('id'=>$comment_id));
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'pingjia'=>0,
			'taskid'=>intval($postdata['taskid']),
			'workermid'=>intval($postdata['workermid']),
			'createtime'=>TIMESTAMP,
		);
		$data=array_merge($insert,$data);
		$this->pdo_insert('survey',$data);
		if($postdata['taskid']){
			$this->update('task',array('ispingjia'=>1),array('id'=>$insert['taskid'],'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('评价成功！','','goback');
}
?>